package com.sky.service.impl;

import com.sky.constant.UserConstant;
import com.sky.exception.ParamErrorException;
import com.sky.service.ShopService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ShopServiceImpl implements ShopService {

    @Resource
    private RedisTemplate redisTemplate;

    /**
     * 设置店铺状态
     *
     * @param status
     */
    @Override
    public void setShopStatus(Integer status) {
        // 验证状态参数
        if (!UserConstant.validateStatusLegal(status)) {
            throw new ParamErrorException("店铺状态参数不合法");
        }

        redisTemplate.opsForValue().set(UserConstant.SHOP_STATUS_KEY, status);
    }

    /**
     * 获取店铺状态
     *
     * @return
     */
    @Override
    public Integer getShopStatus() {
        return (Integer) redisTemplate.opsForValue().get(UserConstant.SHOP_STATUS_KEY);
    }
}
